<template>
    <div>
        <div>
            <h1>已转出人数:{{toNemPeople.length}}人，未转人数{{noToNewPeople.length}}人</h1>
            <!-- <el-card  class="flex-row" style="width: 100%;text-align:left;">
                <div  class="flex-row" style="margin: 10px;">
                    <span style="font-size: 14px;margin-right: 10px;">智慧审核:</span>
                    <el-switch v-model="autoAudit"></el-switch>
                </div>
                <div style="font-size: 14px;margin: 10px;">智慧审核是根据您的预设自动审批转出申请。您需要挂着软件且电脑不能是睡眠模式。</div>
                <xx-table
                v-loading="loading"
                :showDefalutButton="false"
                :showDefalutExpand="false"
                :showDefalutTools="false"
                :tableData="auditTableData">
                </xx-table>
            </el-card> -->
            <el-card>
                <el-badge :value="noToNewPeople.length">
                    <span>未转名单</span>
                </el-badge>
                <el-divider></el-divider>
                <div class="el-tags">
                    <el-tag v-for="(item, i) in noToNewPeople" :key="i">{{item.applicantMName}}</el-tag>
                </div>
            </el-card>
        </div>
        <xx-table
        v-loading="loading"
        :showDefalutButton="false"
        :showDefalutExpand="false"
        :showDefalutTools="false"
        :tableData="tableData">
            <template v-slot:auditStatus="slotProps">
                {{auditStatusToChinese(slotProps.item.auditStatus)}}
            </template>
        </xx-table>
    </div>
</template>

<script>
import XxTable from '../../components/XxTable.vue'
export default {
    components: { XxTable },
    data() {
        return {
            loading: true,
            tableData: {
                pages: 1,
                header: [
                    {
                        label: '姓名',
                        width: '150',
                        prop: 'applicantMName'
                    },
                    {
                        label: '状态',
                        width: '150',
                        prop: 'auditStatus',
                        type: 'no-editslot'
                    },
                    {
                        label: '转入团支部',
                        width: '',
                        prop: 'newName'
                    },
                    {
                        label: '申请时间',
                        width: '150',
                        prop: 'createTime'
                    }
                ],
                data: []
            },
            auditTableData: {
                pages: 1,
                header: [
                    {
                        label: '姓名',
                        width: '',
                        prop: 'applicantMName'
                    },
                    {
                        label: '状态',
                        width: '',
                        prop: 'auditStatus',
                        type: 'no-editslot'
                    },
                    {
                        label: '转入团支部',
                        width: '',
                        prop: 'newName'
                    },
                    {
                        label: '申请时间',
                        width: '',
                        prop: 'createTime'
                    }
                ],
                data: []
            },
            toNemPeople: [],
            noToNewPeople: [],
            autoAudit: false
        }
    },
    computed: {},
    async mounted() {
        console.log(this.$store.state.fullName)
        const people = (await this.getMemberList())
        this.toNemPeople = people.filter(e => {
            return e.newName != this.$store.state.fullName
        })
        this.noToNewPeople = people.filter(e => {
            return !this.toNemPeople.find(f => { return f.applicantMName == e.applicantMName })
        })
        this.tableData.data = this.toNemPeople
    },
    methods: {
        async getMemberList() {
            const res = await fetch('https://tuanapi.12355.net/orgTransfer/all/haveTodoList?page=1&rows=100&_=1645579493151', {
                headers: {
                    accept: 'application/json, text/javascript, */*; q=0.01',
                    'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
                    authorize_name: this.$store.state.oid,
                    'cache-control': 'no-cache',
                    'content-type': 'application/json',
                    pragma: 'no-cache',
                    'sec-ch-ua': '"Chromium";v="92", " Not A;Brand";v="99", "Microsoft Edge";v="92"',
                    'sec-ch-ua-mobile': '?0',
                    'sec-fetch-dest': 'empty',
                    'sec-fetch-mode': 'cors',
                    'sec-fetch-site': 'same-site',
                    Cookie: this.$store.state.cookie
                },
                referrer: 'https://tuan.12355.net/',
                referrerPolicy: 'strict-origin-when-cross-origin',
                body: '{"name":"","auditStatus":"","rewardStatus":"","deletedState":"","mobile":"","disabled":"","developmentMemberNumber":"","leagueForYears":"","volunteerServiceHoursForYear":"","page":1,"pageSize":100}',
                method: 'POST',
                mode: 'cors',
                credentials: 'include'
            })
            this.loading = false
            const temp = await res.json()
            console.log(temp)
            return temp.rows.reverse()
        },
        auditStatusToChinese(auditStatus) {
            const auditStatusMap = {
                5: '转接成功',
                4: '转入团支部的上级待审核',
                3: '转入团支部待审核',
                2: '转出团支部的上级待审核'
            }
            return auditStatusMap[auditStatus]
        }
    }
}
</script>

<style
XxTable>

</style>
